﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using Converter;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using System.Resources;
using System.Reflection;
using ConfigurationNghiepVu;

namespace csla4Skeleton.UI.SL.NghiepVu.Kho.K_PhieuNhapKho
{
    public partial class FormNguoiGiao : ChildWindow
    {
        public object model;
        public NghiepVuType type;
        K_PhieuNhapKho_ChildWindow k_PhieuNhapKho_ChildWindow;
        public FormNguoiGiao(object model, NghiepVuType type)
        {        
            LocalizationConverter converter = new LocalizationConverter();
            converter.LocalResourceManager = new ResourceManager("csla4Skeleton.UI.SL.NghiepVu.Kho.K_PhieuNhapKho.Resources", Assembly.GetExecutingAssembly());
            this.Resources.Add("Localization", converter);
            InitializeComponent();
            this.type = type;
            this.model = model;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {

            string nguoiNop = this.NguoiGiaoTextBox.Text;
            k_PhieuNhapKho_ChildWindow = new K_PhieuNhapKho_ChildWindow(nguoiNop, this.model, this.type);
            k_PhieuNhapKho_ChildWindow.Show();

            k_PhieuNhapKho_ChildWindow.Visibility = Visibility.Collapsed;
            this.OKItemButton.IsEnabled = false;
            this.CancelItemButton.IsEnabled = false;

            k_PhieuNhapKho_ChildWindow.LapPhieuNhapCompleteted += new EventHandler(OnLapPhieuNhapCompleteted);
            k_PhieuNhapKho_ChildWindow.OnClosedChildWindow += new EventHandler(OnClosedWindow);
         
            
            
        }
        private void OnClosedWindow(object sender, EventArgs e)
        {
            this.Close();
        }
        private void OnLapPhieuNhapCompleteted(object sender, EventArgs e)
        {
            
            if (k_PhieuNhapKho_ChildWindow.CountSave == 0)
            {

               MessageBoxResult result = MessageBox.Show("Bạn có muốn xem phiếu nhập ?", "Xem phiếu nhập", MessageBoxButton.OKCancel);

                if (result == MessageBoxResult.OK)
                {
                    k_PhieuNhapKho_ChildWindow.Visibility = Visibility.Visible;
                    k_PhieuNhapKho_ChildWindow.CountSave++;

                }
                else
                {
                    k_PhieuNhapKho_ChildWindow.CountSave++;
                    k_PhieuNhapKho_ChildWindow.Close();
                }
            }
            else
            {
                k_PhieuNhapKho_ChildWindow.Close();
            }
           
        }
    }
}

